public class Test {
    public static void main(String[] args) {
        String str = "12";
        String str1 = "11";
        System.out.println(str.equals(str1));//false

        String str2 = null;
        String str3 = "11";
        System.out.println(str2.equals(str3));
        //Exception in thread "main" java.lang.NullPointerException
    }

    public static void main7(String[] args) {
        String str = "11";
        String str1 = new String("1") + new String("1");
        str1.intern();//手动入池
        System.out.println(str == str1);//false
        System.out.println(str.equals(str1));//true
    }

    public static void main6(String[] args) {
//        String str = "11";
        String str1 = new String("1") + new String("1");
        str1.intern();
        String str = "11";
//        System.out.println(str == str1);//false
        System.out.println(str == str1);//true
    }

    public static void main5(String[] args) {
            String str = "hello";
            String str1 = "he" + "llo";
            //此时他两都是常量，编译时候就已经确定好了是“hello”
            String str2 = "he";
            String str3 = str2 + "llo";
            //此时str3是一个变量，编译的时候不知道是啥
            System.out.println(str == str1);//true
            System.out.println(str == str3);//false
    }

    public static void main4(String[] args) {
        String str = "hello";
        String str1 = "hello";
        System.out.println(str == str1);//true
    }

    public static void main3(String[] args) {
        String str = "hello";
        String str1 = new String("hello");
        System.out.println(str == str1);
    }

    public static void main2(String[] args) {
        String str = "hello";
        String str1 = str;
        System.out.println(str);//hello
        System.out.println(str1);//hello
        str = "world";
        System.out.println(str);//world
        System.out.println(str1);//hello

    }

    public static void main1(String[] args) {
        String str = "hello";
        //调用构造方法进行构造对象
        String str1 = new String("hello");

        char[] chars = {'a','b','c'};
        String str2 = new String(chars);
        System.out.println(str2);

    }
}
